if ( booleanExpression ){
    one or more statements
}else {
    one or more statements }

A good answer might be:

Yes. Logically it is the same as:

if ( booleanExpression )
{
    one or more statements
}
else 
{
    one or more statements 
}

Some programmers use the first style to "save" lines. This was once desirable when terminals could display only 23 lines. But the style leads to errors and extra debugging time.


Asking the Right Question

Say that you are shopping at the Mall and find a $44.95 sweater you like, but (due to an impulsive cookie purchase) you might not have enough money to buy it. Here is a program that decides if you get the sweater:

import java.io.*;
class SweaterPurchase
{
  public static void main (String[] args) throws IOException
  { 
    final int price = 4495;    // price in cents

    BufferedReader stdin = 
        new BufferedReader ( new InputStreamReader( System.in ) );
 
    String inData;
    int    cash;                       

    System.out.println("How much do you have, in pennies?");
    inData = stdin.readLine();
    cash   = Integer.parseInt( inData );     
    
    if (  __________________ )
      System.out.println("You can buy the sweater" );
    else
    {
      System.out.println("You can't buy the sweater" );
      System.out.println("You need $" + 
        (price-cash)/100 + "." + (price-cash)%100 + " more." );
    }

  }
}

The reserved word final in the fifth line says that the value held in price will not change during the run of the program. When you use final, the compiler will not let you write a statement that tries to change the value. This is useful for preventing bugs.

QUESTION 7:

What boolean expression should be in the blank? (Assume that there is no sales tax.)